< previous page page_305 next page >

Page 305
Now consider what happens if you use the AND operator with each of these values:
BIT0 And 5 -> 001 And 101 -> 001
BIT1 And 5 -> 010 And 101 -> 000
BIT2 And 5 -> 100 And 101 -> 100
When a bit in the constant is 0, the resulting bit is forced to be 0that's the nature of the AND operator. When a bit in the constant is 1, the resulting bit depends on the value of the second parameterin this case, the number 5. The constant, in effect, serves as a mask, allowing only those bits that you select in the result. In fact, constants used in this manner are often referred to as mask constants.
So, does our window have a horizontal scrollbar? To find out, we use the AND operator with the WS_HSCROLL mask constant:
style &And WS_HSCROLL -> &H1A00000 And &H100000 -> 0
You can draw out the binary values for yourself if you wish.
Does it have a vertical scrollbar?
style &And WS_VSCROLL -> &H1A00000 And &H200000 -> &H200000
The WS_VSCROLL bit is set in the style, so the window does have a vertical scrollbar. You can take advantage of the fact that the resulting number is non-zero only if the bits identified by the mask are set. The If/Then statement will interpret the &H200000 value as True, so the statement
If style& And WS_VSCROLL Then
will execute the code within the condition block if the vertical scrollbar is present.
The following excerpt from the Winview.vbp program in Chapter 5 of my Win32 API book shows how you can build a string describing the styles of a window. An introduction to window and class styles can be found in Chapter 2 of that book:
7017a6ead0e3c4111b47a554df321e9f.gif
If style& And WS_BORDER Then
    outstring$ = outstring$ + "WS_BORDER" + crlf$
End If
If style& And WS_DISABLED Then
    outstring$ = outstring$ + "WS_DISABLED" + crlf$
End If
If style& And WS_HSCROLL Then
    outstring$ = outstring$ + "WS_HSCROLL" + crlf$

 
< previous page page_305 next page >